<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE HTML>
<html>
<head>
<script type="text/javascript" src="js/jquery-min.js"></script>
<title>My JSP 'setuser.jsp' starting page</title>

<link href="img/ico.ico" rel="shortcut icon">

<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css" />
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

</head>

<body>
	<%@ include file="pagetop/pagetitle.jsp"%>
	<div style="padding-left: 15%;">
		<i class="icon-home"></i><a href="index.action" style="font-size: 18px;">回主页</a>&gt;&gt;&gt;&gt;&gt;修改密码(${user.username })
		<h2 style="font-family: 方正静蕾简体;">账号设置</h2>
		<span style="font-family: 方正静蕾简体;">${user.username}</span><br />
		<hr/>
		<form action="updateUser.action">
			请输入原密码：<input type="password" name="oldpassword" /><span
				class="tishi1"></span><br /> 请输入新密码：<input type="password"
				name="newpassword" /><span class="tishi2"></span><br /> 确认密码:<input
				type="password" name="confirmpassword" /><span class="tishi3"></span>
		</form>
		<input type="button" value="确认修改" /> <span class="relogin"></span>
	</div>
</body>
<script type="text/javascript">
	$(function() {
		$(".tishi1").text("");
		$(".tishi2").text("");
		$(".tishi3").text("");
		$("input[type='button']")
				.click(
						function() {
							if ($("input[name='oldpassword']").val() == "") {
								$(".tishi1").text("请输入原密码!");
								$(".tishi1").css("color", "red");
								return false;
							} else if ($("input[name='newpassword']").val() == "") {
								$(".tishi2").text("请输入新密码!");
								$(".tishi2").css("color", "red");
								return false;
							} else if ($("input[name='confirmpassword']").val() == "") {
								$(".tishi3").text("请输入确认密码!");
								$(".tishi3").css("color", "red");
								return false;
							} else if ($("input[name='confirmpassword']").val() != $(
									"input[name='newpassword']").val()) {
								$(".tishi3").text("两次新密码不一致!请重新输入....");
								$(".tishi3").css("color", "red");
								return false;

							} else if ($("input[name='confirmpassword']").val() == $(
									"input[name='newpassword']").val()) {
								$
										.post(
												"updateUser.action",
												{
													"newpassword" : $(
															"input[name='newpassword']")
															.val(),
													"oldpassword" : $(
															"input[name='oldpassword']")
															.val()
												},
												function(data) {
													if (data) {//修改成功，提示重新登录
														$(".relogin")
																.text(
																		"修改成功,请您重新登录,将跳向登录页面....");
														setTimeout(
																function tiaozhuan() {
																	window.location.href = "relogin.action?task=login";
																}, 3000);
													}
												});
							}
						});

		$("input[name='newpassword']").focus(function() {
			$(".tishi3").text("");
			$(".tishi2").text("");
		});

		$("input[name='confirmpassword']").blur(function() {
			if ($(this).val() != $("input[name='newpassword']").val()) {
				$(".tishi3").css("color", "red");
				$(".tishi3").text("两次新密码不一致!请重新输入....");
				return false;
			}
			;
		});

		$("input[name='oldpassword']").focus(function() {
			$(".tishi1").text("");
		});
		$("input[name='confirmpassword']").focus(function() {
			$(".tishi3").text("");
		});
		$("input[name='oldpassword']").blur(function() {
			//验证原密码是否正确？？
			var oldpassword = $("input[name='oldpassword']").val();
			if (oldpassword != "") {
				$.post("verifyOldpassword.action", {
					"oldpassword" : oldpassword
				}, function(data) {
					if (data) {
						$(".tishi1").text("√");
						$(".tishi1").css("color", "green");
					} else if (!data) {
						$(".tishi1").css("color", "red");
						$(".tishi1").text("您输入的原密码有误,请重新输入...");
						return false;
					}
				});
			}
		});
	});
</script>
</html>
